//
//  TableViewCell.m
//  TestForReactiveCocoa
//
//  Created by liangshangjia on 16/2/17.
//  Copyright © 2016年 Sami-Network. All rights reserved.
//

#import "TableViewCell.h"

#define cell_height UISIZE_CONVERT(230)
#define title_fontSize 26

@interface TableViewCell ()
@property (nonatomic, strong) UIView *separatorTop;
@property (nonatomic, strong) UIView *separatorBottom;
@end
@implementation TableViewCell
- (void)initialize
{
    [super initialize];
    
    _indexImageView = [[UIImageView alloc]init];
    _indexImageView.contentMode = UIViewContentModeScaleAspectFill;
    _indexImageView.clipsToBounds = YES;
    [self.contentView addSubview:self.indexImageView];
    
    _separatorTop = [[UIView alloc]init];
    _separatorTop.backgroundColor = [UIColor blackColor];
//    [self.contentView addSubview:self.separatorTop];
    
    _separatorBottom = [[UIView alloc]init];
    _separatorBottom.backgroundColor = UIColorHex(e5e5e5);
    [self.contentView addSubview:self.separatorBottom];

    _titleLabel = [[UILabel alloc]init];
    _titleLabel.textColor =  UIColorHex(10151b);
    _titleLabel.font = DEFAULT_TEXT_FONT(title_fontSize);
    _titleLabel.numberOfLines = 2;

    [self.contentView addSubview:self.titleLabel];
}


+ (CGFloat)cellHeightWithEntity:(id)entity atIndex:(NSInteger)index
{
    return cell_height;
}


- (void)configureCellWithEntity:(Model *)entity
{
    
    [super configureCellWithEntity:entity];

    [self.titleLabel setAttributedText:[entity.Location attributedStringWithLineSpacing:UISIZE_CONVERT(4)]];
    
    @weakify(self);
    [self.indexImageView setImageWithURL:QINIU_WIDTHLIMIT_URL(entity.IndexImage,cell_height*2)
                             placeholder:nil options:YYWebImageOptionSetImageWithFadeAnimation
                                progress:nil
                               transform:^UIImage *(UIImage *image, NSURL *url) {
                                   @strongify(self);
                                   CGSize size = CGSizeMake(self.indexImageView.width*2,self.indexImageView.height*2);
                                   return [[image imageByResizeToSize:size
                                                          contentMode:UIViewContentModeScaleToFill]
                                           imageByRoundCornerRadius:/*size.width/2*/UISIZE_CONVERT(30)
                                           borderWidth:.5f
                                           borderColor:[UIColor lightGrayColor]];
                               }
                              completion:nil];
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    CGRect frame = self.contentView.frame;
    frame.origin.x = 0;
    frame.origin.y = 0;
    frame.size.height -= UISIZE_CONVERT(5);
    frame.size.width = frame.size.height;
    self.indexImageView.frame = frame;
    
    frame = self.contentView.frame;
    frame.size.height = .5f;
    self.separatorTop.frame = frame;
    
    frame.origin.x = self.indexImageView.width + UISIZE_CONVERT(20.f);
    frame.origin.y = self.contentView.height - frame.size.height;
    frame.size.width = self.contentView.width - frame.origin.x;
    self.separatorBottom.frame = frame;
    
    frame.origin.y = UISIZE_CONVERT(20.f);
    frame.size.width -= UISIZE_CONVERT(20.f);
    frame.size.height = UISIZE_CONVERT(title_fontSize) * 3 + UISIZE_CONVERT(4);
    self.titleLabel.frame = frame;
}






@end
